package com.com.itext.day4;

import com.itextpdf.forms.PdfAcroForm;
import com.itextpdf.forms.fields.PdfFormField;
import com.itextpdf.io.font.PdfEncodings;
import com.itextpdf.kernel.font.PdfFont;
import com.itextpdf.kernel.font.PdfFontFactory;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfReader;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Paragraph;

import java.io.IOException;
import java.util.Map;

public class demo3 {
    public static void main(String[] args) throws Exception {
        PdfReader reader = new PdfReader("D:\\测试pdf\\demo1.pdf");
        PdfDocument pdf = new PdfDocument(new PdfReader("D:\\测试pdf\\demo1.pdf"),new PdfWriter("D:\\测试pdf\\day4_3.pdf"));
        Document doc = new Document(pdf);
        PdfAcroForm from = PdfAcroForm.getAcroForm(pdf,true);
        Map<String, PdfFormField> map = from.getFormFields();
        PdfFont font = PdfFontFactory.createFont("C:/Windows/Fonts/simyou.ttf", PdfEncodings.IDENTITY_H,true);
        Paragraph p = new Paragraph("测试数据").setFont(font);
        map.get("hkzl").setValue(p.toString());
        from.flattenFields();
        pdf.close();
    }
}
